package com.example.widget.view

import com.example.base.BaseActivity
import com.example.base.commonView.CommonDivider
import com.example.base.commonView.CommonTheme
import com.example.base.commonView.TitleBar
import android.os.Bundle
import androidx.compose.foundation.ScrollableColumn
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ContextAmbient
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.annotatedString
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.base.ui.orange

class TextShowActivity : BaseActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            showViews()
        }
    }

    @Composable
    private fun showViews() {
        val context = ContextAmbient.current as BaseActivity
        CommonTheme {
            Column(modifier = Modifier.fillMaxSize()) {
                TitleBar(title = "Text") {
                    context.finish()
                }

                ScrollableColumn(modifier = Modifier.fillMaxSize()) {
                    Text(
                        text = "文本展示",
                        color = orange,
                        modifier = Modifier.padding(horizontal = 20.dp, vertical = 10.dp),
                        style = TextStyle(
                            fontSize = 20.sp
                        )
                    )

                    CommonDivider()

                    Text(
                        text = "文本展示",
                        color = orange,
                        modifier = Modifier.padding(horizontal = 20.dp, vertical = 10.dp),
                        style = TextStyle(
                            fontSize = 20.sp,
                            fontStyle = FontStyle.Italic
                        )
                    )

                    CommonDivider()

                    Text(
                        text = "文本展示",
                        color = orange,
                        fontSize = 20.sp,
                        fontWeight = FontWeight.Bold,
                        modifier = Modifier.padding(horizontal = 20.dp, vertical = 10.dp)
                    )

                    CommonDivider()

                    val text = annotatedString {
                        append("文本展示文本展示")
                        addStyle(style = SpanStyle(color = Color.Blue), 0, 4)
                        addStyle(style = SpanStyle(color = Color.DarkGray), 4, 8)
                    }

                    Text(
                        text = text,
                        fontSize = 20.sp,
                        fontWeight = FontWeight.Bold,
                        modifier = Modifier.padding(horizontal = 20.dp, vertical = 10.dp)
                    )
                }
            }
        }
    }
}